package com.yw.swagger.service.serviceImpl;

import com.yw.swagger.mapper.WebContentsMapper;
import com.yw.swagger.mapper.WebModelsrMapper;
import com.yw.swagger.model.WebContents;
import com.yw.swagger.model.WebModels;
import com.yw.swagger.service.WebContentsService;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author: Abeiv
 * @Description:
 * @Date: 2019/10/26 10:43
 */
@Service
public class WebContentsServiceImpl implements WebContentsService {

    @Autowired
    private WebContentsMapper webContentsMapper;
    @Autowired
    private WebModelsrMapper webModelsrMapper;
    //添加工作动态
    @Override
    public int insertContentsWork(WebContents webContents) {
        //查询工作动态信息
        WebModels webModels=webModelsrMapper.selectWebModelsr("工作动态");
        webContents.setModelID(webModels.getModuleID());
        webContents.setModelParentID(webModels.getParentModuleID());
        webContents.setSendTime(new Date());
        //执行添加WebContents
        return webContentsMapper.insertContentsWork(webContents);
    }

    @Override
    public int insertContentsInform(WebContents webContents) {
        //查询通知公告信息
        WebModels webModels=webModelsrMapper.selectWebModelsr("通知公告");
        webContents.setModelID(webModels.getModuleID());
        webContents.setModelParentID(webModels.getParentModuleID());
        webContents.setSendTime(new Date());
        //执行添加WebContents
        return webContentsMapper.insertContentsWork(webContents);
    }

    @Override
    public int insertContentsAffairs(WebContents webContents) {
        //查询政务公开信息
        WebModels webModels=webModelsrMapper.selectWebModelsr("政务公开");
        webContents.setModelID(webModels.getModuleID());
        webContents.setModelParentID(webModels.getParentModuleID());
        webContents.setSendTime(new Date());
        //执行添加WebContents
        return webContentsMapper.insertContentsWork(webContents);
    }

    @Override
    public int insertContentsSpeak(WebContents webContents) {
        //查询领导讲话信息
        WebModels webModels=webModelsrMapper.selectWebModelsr("领导讲话");
        webContents.setModelID(webModels.getModuleID());
        webContents.setModelParentID(webModels.getParentModuleID());
        webContents.setSendTime(new Date());
        //执行添加WebContents
        return webContentsMapper.insertContentsWork(webContents);
    }

    @Override
    public int insertContentsSpecial(WebContents webContents) {
        //查询专题栏目信息
        WebModels webModels=webModelsrMapper.selectWebModelsr("专题栏目");
        webContents.setModelID(webModels.getModuleID());
        webContents.setModelParentID(webModels.getParentModuleID());
        webContents.setSendTime(new Date());
        //执行添加WebContents
        return webContentsMapper.insertContentsWork(webContents);
    }

    @Override
    public int insertContentsData(WebContents webContents) {
        //查询文件资料信息
        WebModels webModels=webModelsrMapper.selectWebModelsr("文件资料");
        webContents.setModelID(webModels.getModuleID());
        webContents.setModelParentID(webModels.getParentModuleID());
        webContents.setSendTime(new Date());
        //执行添加WebContents
        return webContentsMapper.insertContentsWork(webContents);
    }

    @Override
    public int insertContentsSystem(WebContents webContents) {
        //查询规章制度信息
        WebModels webModels=webModelsrMapper.selectWebModelsr("规章制度");
        webContents.setModelID(webModels.getModuleID());
        webContents.setModelParentID(webModels.getParentModuleID());
        webContents.setSendTime(new Date());
        //执行添加WebContents
        return webContentsMapper.insertContentsWork(webContents);
    }

    @Override
    public int insertContentsStudy(WebContents webContents) {
        //查询学习园地信息
        WebModels webModels=webModelsrMapper.selectWebModelsr("学习园地");
        webContents.setModelID(webModels.getModuleID());
        webContents.setModelParentID(webModels.getParentModuleID());
        webContents.setSendTime(new Date());
        //执行添加WebContents
        return webContentsMapper.insertContentsWork(webContents);
    }

    @Override
    public int insertContentsPubilc(WebContents webContents) {
        //查询公共信息信息
        WebModels webModels=webModelsrMapper.selectWebModelsr("公共信息");
        webContents.setModelID(webModels.getModuleID());
        webContents.setModelParentID(webModels.getParentModuleID());
        webContents.setSendTime(new Date());
        //执行添加WebContents
        return webContentsMapper.insertContentsWork(webContents);
    }
    //分页查询某模块信息
    @Override
    public List<WebContents> seleCtcontentsAll(String modelId) {
        List<WebContents> l = webContentsMapper.seleCtcontentsAll(modelId);
        for (WebContents wc : l){
            Document document = Jsoup.parse(wc.getContents());
            wc.setHtmlContents(document.text());
        }
        return l;
    }


    //查询WebContents表详细信息
    @Override
    public WebContents seleCtcontentsSend(String id) {
        return webContentsMapper.seleCtcontentsSend(id);
    }
    //删除信息
    @Override
    public int deleteContents(String id) {
        String[]ids=id.split(",");
        return webContentsMapper.deleteContents(ids);
    }
    //审核信息
    @Override
    public int contentsAudit(String id) {
        return webContentsMapper.contentsAudit(id);
    }
    //未审核信息
    @Override
    public List<WebContents> selectNotAudit() {
        List<WebContents> webContents=webContentsMapper.selectNotAudit();
        for (WebContents contents:webContents){
            //查询模块名字
            String modelName=webModelsrMapper.selectModelsName(contents.getModelID());
            contents.setModelName(modelName);
        }
        return webContents;
    }


    @Override
    public WebModels seleWebModelByName(String model){
        return webModelsrMapper.selectWebModelsr(model);
    }

    //查询5张图片
    @Override
    public List<WebContents> selectImgUrl() {
        return webContentsMapper.selectImgUrl();
    }
}
